﻿/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#include "Realmd/Application.h"
#include <csignal>
using namespace Shared::Util;


/* 主系统 */
RealmdSystem *g_RealmdSys = NULL;

RealmdApplication::RealmdApplication(void)
    : Application("Realmd", "./Realmd.ini")
    , _realmdSystem()
{

}

RealmdApplication::~RealmdApplication(void)
{

}

void RealmdApplication::onDefineOptions(OptionSet& options)
{
    Application::onDefineOptions(options);
}

int RealmdApplication::onOption(const std::string& name, const std::string& arg)
{
    return Application::onOption(name, arg);
}

void RealmdApplication::onSignal(int signal)
{
    _realmdSystem.onSignal(signal);
}

int RealmdApplication::onInitialize(void)
{
    sharedLog.outString("[Realmd]");
    sharedLog.outString("<Ctrl-C> to stop.\n"
        "  __  __      _  _  ___  ___  ___                         \n"
        " |  \\/  |__ _| \\| |/ __|/ _ \\/ __|        We Love      \n"
        " | |\\/| / _` | .` | (_ | (_) \\__ \\      Vanilla Wow    \n"                                         
        " |_|  |_\\__,_|_|\\_|\\___|\\___/|___/                    \n"
        "                                        ____              \n"
        " For help and support please visit:    /_  /___ _ _ ___   \n" 
        " Website: https://getmangos.eu          / // -_) '_/ _ \\ \n" 
        "    Wiki: http://github.com/mangoswiki /___\\___|_| \\___/\n" 
        );

    if (!_realmdSystem.initialize()) {
        return EXIT_SUBSYSTEM;
    }
    g_RealmdSys = &_realmdSystem;

    hookSignal(SIGINT);
    return EXIT_OK;
}

void RealmdApplication::onUninitialize(void)
{
    _realmdSystem.uninitialize();
}

int RealmdApplication::main(std::vector<std::string>& unknownArgs)
{
    _realmdSystem.run();
    return EXIT_OK;
}